﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppStore.Domain.Entities
{
    public class Cart
    {
        List<Application> lineCollection = new List<Application>();
        
        public void AddItem(Application application)
        {
            lineCollection.Add(application);
        }

        public void RemoveItem(Application application)
        {
            lineCollection.Remove(lineCollection.Single(a => a.applicationId == application.applicationId));
        }

        public decimal CalculateTotalValue()
        {
            return lineCollection.Sum(a => a.price);
        }

        public void Clear()
        {
            lineCollection.Clear();
        }

        public IEnumerable<Application> Lines
        {
            get { return lineCollection; }
        } 
    }
}
